//
//  DKAuthStepViewController.m
//  DanKU
//
//  Created by 吴斌 on 2023/10/29.
//

#import "DKAuthStepViewController.h"
#import "DKAuthHeadStepInfoCell.h"
#import "DKAuthBaseStepInfoCell.h"
#import "DKAuthFaceFirstCell.h"
#import "DKAuthFaceSecondCell.h"
#import "DKAuthPrivacyAgreementCell.h"
#import "DKAuthStartAlertView.h"
#import "DKAuthScuessCell.h"
#import "DKAuthFailView.h"
#import "DKAuthFaceFinishCell.h"

#import "DKPanCardAuthCell.h"
#import "DKPanCardAuthKtpCell.h"
#import "DKBaseInfoAuthCell.h"
#import "DKAuthNextCell.h"
#import "DKPanCardPhotoController.h"

#import "DKContactAuthCell.h"
#import "DKBankCardAuthCell.h"
#import "DKAuthScuessAlertView.h"
#import "DKTabBarViewController.h"

#import "DKAuthBackAlertView.h"
#import "DKAuthFeedBackAlertView.h"
#import "DKAuthPanCardSubmitView.h"
//#import "DKAuthStepView.h"
//#import "DKAuthSecurityView.h"
//#import "DKAuthBaseStepView.h"
//#import "DKAuthFaceView.h"
//#import "DKAuthStartAuthenticationView.h"
//#import "DKAuthCertificationCamorView.h"
@interface DKAuthStepViewController ()<UITableViewDelegate,UITableViewDataSource,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
//@property (nonatomic, strong)DKAuthStepView * dk_AuthStepView;
@property (nonatomic, strong)UITableView * dk_AuthStepTableView;
@property (nonatomic, strong)UIImagePickerController *imagePickerCtrl;

@property (nonatomic, strong)NSString * authStepStatus;//1.face检测  2.card检测 3.baseInfo检测 4.联系人认证 5.银行卡认证
@property (nonatomic, strong)NSString * authFaceStatus;//1.准备开始检测 2.开始检测 3.检测完成
@property (nonatomic, strong)NSString * authCardStatus;//1.准备开始检测 2.ktp确认

@property (nonatomic,strong) DKAuthLivenConfigModel * dk_AuthLivenConfigMdl;//活体策略
@property (nonatomic, strong)DKAuthLiveBase64Model * dk_AuthLiveBase64Mdl;//人脸认证信息

@property (nonatomic,strong) DKAuthPanCardModel * dk_AuthPanCardMdl;//银行卡上传成功信息
@property (nonatomic,assign) BOOL isErrorBankAccount;
@property (nonatomic,assign) BOOL isErrorIFSC;

@property (nonatomic,assign) BOOL isNeedBack;//是否需要认证挽留
@end

@implementation DKAuthStepViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self dk_addSubView];
    [self updataSetp];
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    [self requestUserBrhavRecord:DK_ActionEnter withParmDic:@{}];
}
- (void)dk_addSubView{
    UIImageView* dk_AuthStepBgImgView = [[UIImageView alloc] init];
    dk_AuthStepBgImgView.userInteractionEnabled = YES;
    dk_AuthStepBgImgView.image = DK_GetImage(@"dk_AuthBg");
    [self.view addSubview:dk_AuthStepBgImgView];
    [dk_AuthStepBgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@(DK_IsWidthScale(0)));
    }];
    self.dk_AuthStepTableView = [[UITableView alloc] init];
    self.dk_AuthStepTableView.backgroundColor = UIColor.clearColor;
    self.dk_AuthStepTableView.delegate = self;
    self.dk_AuthStepTableView.dataSource = self;
    self.dk_AuthStepTableView.estimatedRowHeight = 0;
    self.dk_AuthStepTableView.estimatedSectionHeaderHeight = 0;
    self.dk_AuthStepTableView.estimatedSectionFooterHeight = 0;
    self.dk_AuthStepTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.dk_AuthStepTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    self.dk_AuthStepTableView.showsVerticalScrollIndicator = NO;
    self.dk_AuthStepTableView.shouldIgnoreScrollingAdjustment = YES;
    self.dk_AuthStepTableView.shouldRestoreScrollViewContentOffset = YES;
    [self.view addSubview:self.dk_AuthStepTableView];
    [self.dk_AuthStepTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@(DK_IsWidthScale(0)));
        make.top.equalTo(@(DK_SafeAreaTop));
        make.bottom.equalTo(@(DK_IsWidthScale(0)));
    }];
    UIButton * dk_AuthBackBtn = [[UIButton alloc] init];
    [dk_AuthBackBtn setBackgroundImage:DK_GetImage(@"dk_AuthBack") forState:UIControlStateNormal];
    [dk_AuthBackBtn addTarget:self action:@selector(AuthBack) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:dk_AuthBackBtn];
    [dk_AuthBackBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(15)));
        make.top.equalTo(@(DK_IsWidthScale(11)+DK_SafeAreaTop));
        make.width.equalTo(@(DK_IsWidthScale(22)));
        make.height.equalTo(@(DK_IsWidthScale(22)));
    }];
    
    
}
- (void)contartKeFu{
    
}
- (void)AuthBack{
    if(self.isNeedBack){
        WeakSelf(self)
        [DKAuthBackAlertView dk_ShowAuthBackAlertView:^{
            weakSelf.isNeedBack = NO;
        }];
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }
}
- (void)AuthCheckAgreement{
    DKWebViewController * dk_WebViewCtrl = [[DKWebViewController alloc] initWithUrl:DK_PrivacyAgreement withIsNavBar:YES];
    [self.navigationController pushViewController:dk_WebViewCtrl animated:YES];
}
//开始拍照
- (void)makeStartPhoto{
    if(!self.imagePickerCtrl){
        self.imagePickerCtrl = [[UIImagePickerController alloc] init];
        self.imagePickerCtrl.sourceType = UIImagePickerControllerSourceTypeCamera;
        self.imagePickerCtrl.delegate = self;
        self.imagePickerCtrl.modalPresentationStyle = UIModalPresentationOverFullScreen;
        [self presentViewController:self.imagePickerCtrl animated:YES completion:nil];
    }else{
        [self presentViewController:self.imagePickerCtrl animated:YES completion:nil];
    }
}
- (void)makePanCardView{
    WeakSelf(self)
    DKPanCardPhotoController *dk_PanCardPhotoCtrl = [[DKPanCardPhotoController alloc] init];
    dk_PanCardPhotoCtrl.modalPresentationStyle = UIModalPresentationOverFullScreen;
    [self presentViewController:dk_PanCardPhotoCtrl animated:YES completion:^{
            
    }];
//    [self.navigationController pushViewController:dk_PanCardPhotoCtrl animated:YES];
    dk_PanCardPhotoCtrl.PanCardScuessBlock = ^(DKAuthPanCardModel * _Nonnull dk_AuthPanCardMdl) {//银行卡拍照成功
        weakSelf.dk_AuthPanCardMdl = dk_AuthPanCardMdl;
        weakSelf.authCardStatus = @"2";
        [weakSelf.dk_AuthStepTableView reloadData];
    };
//    [dk_PanCardPhotoView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.edges.equalTo(@(DK_IsWidthScale(0)));
//    }];
}
- (void)updataSetp{
    WeakSelf(self)
    if([DKGlobalHelper defaultManager].loanSetpInfoMdl.livenConfig.skipLiven){//为yes，跳过活体认证
        NSMutableDictionary *userInfoDic = [[NSMutableDictionary alloc] init];
        [userInfoDic setObject:@{} forKey:@"data"];
        [userInfoDic setObject:@"LIVENESS_INFO" forKey:@"step"];
        [DKPublicHttp apiSaveUserInfoForAPI:userInfoDic complete:^{//保存用户信息,保存完成之后调用获取下一步接口根据返回值进行跳转

            [DKPublicHttp apiGetNextStepForAPI:@{} complete:^{//获取下一步信息
                [weakSelf updataSetp];
            }];
        }fail:^{
            
        }];
    }
    if([[DKGlobalHelper defaultManager].loanSetpInfoMdl.step isEqualToString: @"LIVENESS_INFO"]){//活体认证
        [DKGlobalHelper defaultManager].livenessStartTime = [NSString getCurrentTimeTimestamp];

        self.authStepStatus = @"1";
        self.authFaceStatus = @"1";
        self.isNeedBack = YES;
    }else if([[DKGlobalHelper defaultManager].loanSetpInfoMdl.step isEqualToString: @"IDENTITY_INFO"]){//id卡验证
        [DKGlobalHelper defaultManager].panCardStartTime = [NSString getCurrentTimeTimestamp];

        [self requestUserBrhavRecordPANCard:DK_ActionConfig withParmDic:[DKGlobalHelper defaultManager].loanSetpInfoMdl.ocrJumpConfig.mj_keyValues];

        //判断是否做过ORC身份认证
        if([DKGlobalHelper defaultManager].loanSetpInfoMdl.idCardOcrDetails&&[DKGlobalHelper defaultManager].loanSetpInfoMdl.ocrJumpConfig){
            weakSelf.dk_AuthPanCardMdl = [[DKAuthPanCardModel alloc] init];
            weakSelf.dk_AuthPanCardMdl.idCardOcrDetails = [DKGlobalHelper defaultManager].loanSetpInfoMdl.idCardOcrDetails;
            weakSelf.dk_AuthPanCardMdl.photoName = [DKGlobalHelper defaultManager].loanSetpInfoMdl.data.ossPanCardPositiveImg;
            weakSelf.dk_AuthPanCardMdl.url = [DKGlobalHelper defaultManager].loanSetpInfoMdl.data.ossPanCardPositiveImgBase;
            self.authStepStatus = @"2";
            self.authCardStatus = @"2";
        }else{
            self.authStepStatus = @"2";
            self.authCardStatus = @"1";
        }
        self.isNeedBack = YES;
    }else if([[DKGlobalHelper defaultManager].loanSetpInfoMdl.step isEqualToString: @"PERSONAL_INFO"]){//基础信息验证
        [DKGlobalHelper defaultManager].infoStartTime = [NSString getCurrentTimeTimestamp];

        self.authStepStatus = @"3";
        self.isNeedBack = YES;
    }else if([[DKGlobalHelper defaultManager].loanSetpInfoMdl.step isEqualToString: @"CONTACT_INFO"]){//联系人验证
        [DKGlobalHelper defaultManager].contactStartTime = [NSString getCurrentTimeTimestamp];

        self.authStepStatus = @"4";
        self.isNeedBack = YES;
    }else if([[DKGlobalHelper defaultManager].loanSetpInfoMdl.step isEqualToString: @"BANK_INFO"]){//银行卡验证
        [DKGlobalHelper defaultManager].bankStartTime = [NSString getCurrentTimeTimestamp];

        self.authStepStatus = @"5";
        self.isNeedBack = YES;
    }
    [self.dk_AuthStepTableView reloadData];
}
- (void)makePrivacyAgreement{
    DKWebViewController * dk_WebViewCtrl = [[DKWebViewController alloc] initWithUrl:DK_PrivacyAgreement withIsNavBar:YES];
    dk_WebViewCtrl.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:dk_WebViewCtrl animated:YES];
}
#pragma mark -- UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
//    if([self.authStepStatus isEqualToString:@"1"]){//face检测
//        return 3;
//    }else if ([self.authStepStatus isEqualToString:@"2"]){//2.card检测
//        return 3;
//    }else if([self.authStepStatus isEqualToString:@"3"]){//3.baseInfo检测
//        return 3;
//    }else if([self.authStepStatus isEqualToString:@"4"]){//4.联系人认证
//        return 3;
//    }else if([self.authStepStatus isEqualToString:@"5"]){//5.银行卡认证
//        return 3;
//    }else{
//        return 3;
//    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0){
        return DK_IsWidthScale(87)+DK_SafeAreaTop;
    }else if (indexPath.row == 1){
        return DK_IsWidthScale(115);
    }else if (indexPath.row == 2){
        if([self.authStepStatus isEqualToString:@"1"]){
            return DK_IsWidthScale(564)+DK_SafeAreaBottom;
        }else if([self.authStepStatus isEqualToString:@"2"]){
            return DK_IsWidthScale(588)+DK_SafeAreaBottom;
        }else if([self.authStepStatus isEqualToString:@"3"]){
            return DK_IsWidthScale(737)+DK_SafeAreaBottom;
        }else if([self.authStepStatus isEqualToString:@"4"]){
            return DK_IsWidthScale(640)+DK_SafeAreaBottom;
        }else if([self.authStepStatus isEqualToString:@"5"]){
            CGFloat bankCardHeight = 0;
            if(self.isErrorBankAccount){
                bankCardHeight += DK_IsWidthScale(34);
            }
            if(self.isErrorIFSC){
                bankCardHeight += DK_IsWidthScale(34);
            }
            return DK_IsWidthScale(667)+DK_SafeAreaBottom + bankCardHeight;
        }else{
            return DK_IsWidthScale(737)+DK_SafeAreaBottom;
        }
    }else{
        return DK_IsWidthScale(50);
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    WeakSelf(self)
    if(indexPath.row == 0){
        DKAuthHeadStepInfoCell * dk_AuthHeadStepInfoCell = [DKAuthHeadStepInfoCell authHeadStepInfoCell:tableView];
        dk_AuthHeadStepInfoCell.dk_AuthStep = self.authStepStatus;
        return dk_AuthHeadStepInfoCell;
    }else if (indexPath.row == 1){
        DKAuthBaseStepInfoCell *dk_AuthBaseStepInfoCell = [DKAuthBaseStepInfoCell authBaseStepCell:tableView];
        dk_AuthBaseStepInfoCell.dk_AuthStep = self.authStepStatus;
        return dk_AuthBaseStepInfoCell;
    }else{
        if([self.authStepStatus isEqualToString:@"1"]){
            if([self.authFaceStatus isEqualToString:@"1"]){
                DKAuthFaceFirstCell *dk_AuthFaceFirstCell = [DKAuthFaceFirstCell authFaceFirstCell:tableView];
                dk_AuthFaceFirstCell.CertificationBlock = ^{//准备拍照认证
                    [weakSelf requestUserBrhavRecord:DK_ActionLiveness_Click withParmDic:@{@"type":@"LIVENESS_INFO"}];

                    [DKAuthStartAlertView dk_ShowAuthStartAlertView:self.view complete:^{//开始拍照认证
                        NSMutableDictionary *checkAuthDic = [[NSMutableDictionary alloc] init];
                        [checkAuthDic setValue:@"LIVENESS_TIMES" forKey:@"authType"];
                        [DKPublicHttp apiCheckIsCanAuthForAPI:checkAuthDic complete:^{
                            //获取活体策略
                            [DKPublicHttp apiAuthLivenConfigForAPI:@{} complete:^(DKAuthLivenConfigModel * _Nonnull dk_AuthLivenConfigMdl) {
                                weakSelf.dk_AuthLivenConfigMdl = dk_AuthLivenConfigMdl;
                                weakSelf.authFaceStatus = @"2";
                                [weakSelf.dk_AuthStepTableView reloadData];
                                
                            }];
                        }];
                       
                    }];
                };
                dk_AuthFaceFirstCell.CheckPrivacyAgreementBlock = ^{
                    [weakSelf makePrivacyAgreement];
                };
                return dk_AuthFaceFirstCell;
            }else if([self.authFaceStatus isEqualToString:@"2"]){

                DKAuthFaceSecondCell *dk_AuthFaceSecondCell = [DKAuthFaceSecondCell authFaceSecondCell:tableView];
                dk_AuthFaceSecondCell.dk_AuthLivenConfigMdl = self.dk_AuthLivenConfigMdl;
                dk_AuthFaceSecondCell.CheckPrivacyAgreementBlock = ^{
                    [weakSelf makePrivacyAgreement];
                };
                dk_AuthFaceSecondCell.FaceAuthScuessBlock = ^(DKAuthLiveBase64Model * _Nonnull dk_AuthLiveBase64Mdl) {
                    
                    [weakSelf requestUserBrhavRecord:DK_ActionLiveness_Success withParmDic:@{@"livenessId":dk_AuthLiveBase64Mdl.livenessId}];

                    weakSelf.dk_AuthLiveBase64Mdl = dk_AuthLiveBase64Mdl;
                    weakSelf.authFaceStatus = @"3";
                    [weakSelf.dk_AuthStepTableView reloadData];
                };
                dk_AuthFaceSecondCell.FaceAuthFailBlock = ^(NSString * _Nonnull msg) {
                    [weakSelf requestUserBrhavRecord:DK_ActionLiveness_Failure withParmDic:@{@"errorMsg":msg}];
                    weakSelf.authFaceStatus = @"1";
                    [weakSelf.dk_AuthStepTableView reloadData];
                };
                return dk_AuthFaceSecondCell;
            }else{
                DKAuthScuessCell *dk_AuthScuessCell = [DKAuthScuessCell authScuessCell:tableView];
                dk_AuthScuessCell.dk_AuthLiveBase64Mdl = self.dk_AuthLiveBase64Mdl;
                dk_AuthScuessCell.StartCardAuthBlock = ^{
                    [DKPublicHttp apiUserRiskForAPI:@"LIVENESS" complete:^{
                        
                    } fail:^{
                        
                    }];
                    
                    [DKPublicHttp apiGetNextStepForAPI:@{} complete:^{//获取下一步信息
                        [weakSelf updataSetp];
                    }];
                };
                dk_AuthScuessCell.AuthPhotoBlock = ^{
                    weakSelf.authFaceStatus = @"2";
                    [weakSelf.dk_AuthStepTableView reloadData];
                };
                dk_AuthScuessCell.CheckPrivacyAgreementBlock = ^{
                    [weakSelf makePrivacyAgreement];
                };
                return dk_AuthScuessCell;
               
            }
        }else if([self.authStepStatus isEqualToString:@"2"]){
            if([self.authCardStatus isEqualToString:@"1"]){
                [self requestUserBrhavRecordPANCard:DK_ActionEnter withParmDic:@{}];
                
                DKPanCardAuthCell *dk_PanCardAuthCell = [DKPanCardAuthCell authPanCardAuthCell:tableView];
                dk_PanCardAuthCell.CheckPrivaryAgmentBlock = ^{
                    DKWebViewController * dk_WebViewCtrl = [[DKWebViewController alloc] initWithUrl:DK_PrivacyAgreement withIsNavBar:YES];
                    [weakSelf.navigationController pushViewController:dk_WebViewCtrl animated:YES];
                };
                dk_PanCardAuthCell.StartPanCardBlock = ^{
                    NSMutableDictionary *checkAuthDic = [[NSMutableDictionary alloc] init];
                    [checkAuthDic setValue:@"PAN_FRONT_TIMES" forKey:@"authType"];
                    [DKPublicHttp apiCheckIsCanAuthForAPI:checkAuthDic complete:^{
                        [weakSelf requestUserBrhavRecordPANCard:DK_ActionID_Pan_Front_Click withParmDic:@{}];

                        [weakSelf makePanCardView];
                    }];
                };
                return dk_PanCardAuthCell;
            }else{
                DKPanCardAuthKtpCell *dk_PanCardAuthKtpCell = [DKPanCardAuthKtpCell authPanCardAuthKtpCell:tableView];
                dk_PanCardAuthKtpCell.dk_AuthPanCardMdl = self.dk_AuthPanCardMdl;
                dk_PanCardAuthKtpCell.CheckPrivaryAgmentBlock = ^{
                    DKWebViewController * dk_WebViewCtrl = [[DKWebViewController alloc] initWithUrl:DK_PrivacyAgreement withIsNavBar:YES];
                    [weakSelf.navigationController pushViewController:dk_WebViewCtrl animated:YES];
                };
                dk_PanCardAuthKtpCell.NextPanCardBlock = ^(DKAuthPanCardModel * _Nonnull dk_AuthPanCardMdl) {//保存用户信息
                    [weakSelf requestUserBrhavRecordPANCard:DK_ActionClick withParmDic:@{}];

                    NSMutableDictionary *userInfoDataDic = [[NSMutableDictionary alloc] init];
                    [userInfoDataDic setObject:weakSelf.dk_AuthPanCardMdl.photoName forKey:@"ossPanCardPositiveImg"];
                    [userInfoDataDic setObject:weakSelf.dk_AuthPanCardMdl.idCardOcrDetails.name forKey:@"realName"];
                    [userInfoDataDic setObject:weakSelf.dk_AuthPanCardMdl.idCardOcrDetails.idNumber forKey:@"panNo"];
                    NSMutableDictionary *userInfoDic = [[NSMutableDictionary alloc] init];
                    [userInfoDic setObject:userInfoDataDic forKey:@"data"];
                    [userInfoDic setObject:@"IDENTITY_INFO" forKey:@"step"];
                    [DKPublicHttp apiSaveUserInfoForAPI:userInfoDic complete:^{//保存用户信息
                        [DKAuthPanCardSubmitView dk_ShowAuthPanCardSubmitView:YES  withAlertView:weakSelf.view dissAuthPanCardSubmit:^{
                            [DKPublicHttp apiUserRiskForAPI:@"PAN_CARD_FRONT" complete:^{
                                
                            } fail:^{
                                
                            }];
                            [DKPublicHttp apiGetNextStepForAPI:@{} complete:^{//获取下一步信息
                                [weakSelf updataSetp];
                            }];
                        }];
                        [weakSelf requestUserBrhavRecordPANCard:DK_ActionSave withParmDic:@{@"name":weakSelf.dk_AuthPanCardMdl.idCardOcrDetails.name,@"idNum":weakSelf.dk_AuthPanCardMdl.idCardOcrDetails.idNumber,@"panNo":weakSelf.dk_AuthPanCardMdl.idCardOcrDetails.idNumber}];

                    }fail:^{
                        [DKAuthPanCardSubmitView dk_ShowAuthPanCardSubmitView:NO withAlertView:weakSelf.view dissAuthPanCardSubmit:^{
                            
                        }];
                    }];
                };
                dk_PanCardAuthKtpCell.CheckPrivaryAgmentBlock = ^{
                    DKWebViewController * dk_WebViewCtrl = [[DKWebViewController alloc] initWithUrl:DK_PrivacyAgreement withIsNavBar:YES];
                    [weakSelf.navigationController pushViewController:dk_WebViewCtrl animated:YES];
                };
                dk_PanCardAuthKtpCell.StartPanCardBlock = ^{
                    [weakSelf makePanCardView];
                };
                return dk_PanCardAuthKtpCell;
            }
        }else if([self.authStepStatus isEqualToString:@"3"]){
            [self requestUserBrhavRecordBaseCard:DK_ActionEnter withParmDic:@{}];

            DKBaseInfoAuthCell *dk_BaseInfoAuthCell = [DKBaseInfoAuthCell baseInfoAuthCell:tableView];
            dk_BaseInfoAuthCell.RequestScuessBaseInfoBlock = ^{
                [DKPublicHttp apiUserRiskForAPI:@"INFORMATION" complete:^{
                    
                } fail:^{
                    
                }];
                [DKPublicHttp apiGetNextStepForAPI:@{} complete:^{//获取下一步信息
                    [weakSelf updataSetp];
                }];
            };
            dk_BaseInfoAuthCell.CheckPrivateAgrmentBlock = ^{
                DKWebViewController * dk_WebViewCtrl = [[DKWebViewController alloc] initWithUrl:DK_PrivacyAgreement withIsNavBar:YES];
                [weakSelf.navigationController pushViewController:dk_WebViewCtrl animated:YES];
            };
            return dk_BaseInfoAuthCell;
        }else if([self.authStepStatus isEqualToString:@"4"]){//联系人认证
            [self requestUserBrhavRecordContact:DK_ActionEnter withParmDic:@{}];

            DKContactAuthCell *dk_ContactAuthCell = [DKContactAuthCell contactAuthCell:tableView];
            dk_ContactAuthCell.RequestScuessContactAuthBlock = ^{
                [DKPublicHttp apiUserRiskForAPI:@"CONTACT" complete:^{
                    
                } fail:^{
                    
                }];
                [DKPublicHttp apiGetNextStepForAPI:@{} complete:^{//获取下一步信息
                    [weakSelf updataSetp];
                }];
            };
            dk_ContactAuthCell.CheckPrivateAgrmentBlock = ^{
                DKWebViewController * dk_WebViewCtrl = [[DKWebViewController alloc] initWithUrl:DK_PrivacyAgreement withIsNavBar:YES];
                [weakSelf.navigationController pushViewController:dk_WebViewCtrl animated:YES];
            };
            return dk_ContactAuthCell;
        }else if([self.authStepStatus isEqualToString:@"5"]){//银行卡认证
            [self requestUserBrhavRecordBankCard:DK_ActionEnter withParmDic:@{}];

            DKBankCardAuthCell *dk_BankCardAuthCell = [DKBankCardAuthCell bankCardAuthCell:tableView];
            dk_BankCardAuthCell.RequestScuessBankCardAuthBlock = ^{
                [DKPublicHttp apiUserRiskForAPI:@"BANK" complete:^{
                    
                } fail:^{
                    
                }];
                
                [DKPublicHttp apiGetNextStepForAPI:@{} complete:^{//获取下一步信息
                    [DKAuthScuessAlertView dk_ShowAuthScuessAlertView:^{
                        DKTabBarViewController * dk_TabBarViewCtrl = [[DKTabBarViewController alloc] init];
                        dk_TabBarViewCtrl.isAuth = YES;//默认未认证，未认证会再次识别
                        ((AppDelegate*)([UIApplication sharedApplication].delegate)).window.rootViewController = dk_TabBarViewCtrl;
                    }];
                }];
            };
            dk_BankCardAuthCell.CheckPrivateAgrmentBlock = ^{
                DKWebViewController * dk_WebViewCtrl = [[DKWebViewController alloc] initWithUrl:DK_PrivacyAgreement withIsNavBar:YES];
                [weakSelf.navigationController pushViewController:dk_WebViewCtrl animated:YES];
            };
            dk_BankCardAuthCell.CheckErrorBlock = ^(BOOL isErrorBankAccount, BOOL isErrorIFSC) {
                weakSelf.isErrorBankAccount = isErrorBankAccount;
                weakSelf.isErrorIFSC = isErrorIFSC;
                [weakSelf.dk_AuthStepTableView reloadData];
            };
            return dk_BankCardAuthCell;
        }else{
            DKBaseInfoAuthCell *dk_BaseInfoAuthCell = [DKBaseInfoAuthCell baseInfoAuthCell:tableView];
            dk_BaseInfoAuthCell.RequestScuessBaseInfoBlock = ^{
                [DKPublicHttp apiGetNextStepForAPI:@{} complete:^{//获取下一步信息
                    [weakSelf updataSetp];;
                }];
            };
            dk_BaseInfoAuthCell.CheckPrivateAgrmentBlock = ^{
                DKWebViewController * dk_WebViewCtrl = [[DKWebViewController alloc] initWithUrl:DK_PrivacyAgreement withIsNavBar:YES];
                [weakSelf.navigationController pushViewController:dk_WebViewCtrl animated:YES];
            };
            return dk_BaseInfoAuthCell;
        }
    }
}
#pragma mark -- UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info{
    [self.imagePickerCtrl dismissViewControllerAnimated:YES completion:nil];
    WeakSelf(self)
    UIImage * photo = [info objectForKey:UIImagePickerControllerOriginalImage];
    NSData *imageData = [NSString changeImageSizeForData:photo toByte:300000];

    NSMutableDictionary *ossLiveBase64Dic = [[NSMutableDictionary alloc] init];
    [ossLiveBase64Dic setValue:@"" forKey:@"actionId"];
    [ossLiveBase64Dic setValue:self.dk_AuthLivenConfigMdl.livenChannel forKey:@"channelEnum"];
    [DKPublicHttp  apiOssLiveBase64ForAPI:ossLiveBase64Dic withData:imageData complete:^(DKAuthLiveBase64Model * _Nonnull dk_AuthLiveBase64Mdl) {//认证成功
        weakSelf.dk_AuthLiveBase64Mdl = dk_AuthLiveBase64Mdl;
        //活体预处理
        NSDictionary *preLivenessDic = @{@"livenessId":dk_AuthLiveBase64Mdl.livenessId};
        [DKPublicHttp apiPreLivenessForAPI:preLivenessDic complete:^{
            weakSelf.authFaceStatus = @"3";
            [weakSelf.dk_AuthStepTableView reloadData];
        }];
    } fail:^(NSString * _Nonnull msg) {//认证失败
        [DKAuthFailView dk_ShowAuthFailAlertView:^{
           
        }];
    }];
}
- (void)requestUserBrhavRecord:(NSString *)action withParmDic:(NSDictionary *)parmDic{
    [DKPublicHttp apiUserBrhavRecordForAPI:parmDic withPageName:DK_VerifyLiveness withAction:action complete:^{
            
    } fail:^{
            
    }];
}
- (void)requestUserBrhavRecordPANCard:(NSString *)action withParmDic:(NSDictionary *)parmDic{
    [DKPublicHttp apiUserBrhavRecordForAPI:parmDic withPageName:DK_VerifyIdentify withAction:action complete:^{
            
    } fail:^{
            
    }];
}
- (void)requestUserBrhavRecordBaseCard:(NSString *)action withParmDic:(NSDictionary *)parmDic{
    [DKPublicHttp apiUserBrhavRecordForAPI:parmDic withPageName:DK_VerifyBasic withAction:action complete:^{
            
    } fail:^{
            
    }];
}
- (void)requestUserBrhavRecordContact:(NSString *)action withParmDic:(NSDictionary *)parmDic{
    [DKPublicHttp apiUserBrhavRecordForAPI:parmDic withPageName:DK_VerifyContact withAction:action complete:^{
            
    } fail:^{
            
    }];
}
- (void)requestUserBrhavRecordBankCard:(NSString *)action withParmDic:(NSDictionary *)parmDic{
    [DKPublicHttp apiUserBrhavRecordForAPI:parmDic withPageName:DK_VerifyBankcard withAction:action complete:^{
            
    } fail:^{
            
    }];
}
@end
